package com.corpdata.app.contract.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestParam;
import com.corpdata.app.contract.entity.ContractReceivable;
import com.corpdata.app.contract.service.ContractReceivableService;
import com.corpdata.common.domain.DataGridRequestDTO;
import com.corpdata.common.result.Result;
import com.corpdata.system.log.WebLog;
import com.corpdata.core.base.BaseController;

/**
 * 合同应收
 * 
 * @author wu
 * @email 64088839@qq.com
 * @date 2018-07-04 11:12:41
 */
 
@Controller
@RequestMapping("app/contractReceivable")
public class ContractReceivableController extends BaseController{

	@Autowired
	private ContractReceivableService contractReceivableService;
	
	//新增页面
	@GetMapping("/add/{id}")
	public String add(@PathVariable("id") String id,ModelMap map){
		map.put("id", id);
		return "app/contract/receivable/receivable_add";
	}
	
	//保存数据
	@WebLog()
	@ResponseBody
	@RequestMapping("/save")
	public Result save(ContractReceivable record,String contractInfoId,String rent,int interest) throws Exception{
		return contractReceivableService.insert(record, contractInfoId, rent,interest);
	}
	
	//编辑页面
	@RequestMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id,ModelMap map){
		map.put("record", contractReceivableService.findById(id));
		return "app/contract/contractReceivable_edit";
	}
	
	//更新数据
	@WebLog()
	@ResponseBody
	@RequestMapping("/update")
	public Result update(ContractReceivable record){
		return contractReceivableService.update(record);
	}
	
	//删除
	@WebLog()
	@ResponseBody
	@PostMapping("/delete")
	public Result delete(String id){
		return contractReceivableService.deleteById(id);
	}
	
	//删除
	@WebLog()
	@ResponseBody
	@PostMapping("/deleteAll")
	public Result deleteAll(String id){
		return contractReceivableService.deleteAllById(id);
	}
	
	//批量删除
	@WebLog()
	@ResponseBody
	@PostMapping("/deletes")
	public Result deletes(@RequestParam("ids[]") String[] ids){
		return contractReceivableService.deleteByIds(ids);
	}
	
	//详情页面
	@GetMapping("/details/{id}")
	public String details(ModelMap map,@PathVariable("id") String id){
		map.put("record", contractReceivableService.findById(id));
	    return "app/contract/contractReceivable_details";
	}
	
	//列表页面
	@GetMapping("/list")
	public String list(){
	    return "app/contract/contractReceivable_list";
	}
	
	//列表数据
	@ResponseBody
	@RequestMapping("/listdata")
	public String findByPage(DataGridRequestDTO dgRequest){
		return contractReceivableService.findByPage(dgRequest);
	}
	
	//列表页面
	@GetMapping("/list/{type}_{contractId}")
	public String list(ModelMap map,@PathVariable("type")String type,@PathVariable("contractId") String contractId){
		map.put("type", type);
		map.put("contractId", contractId);
	    return "app/contract/receivable/receivable_list";
	}
	//收款
	@WebLog()
	@ResponseBody
	@PostMapping("/shoukuan")
	public Result shoukuan(String id){
		return contractReceivableService.shoukuanById(id);
	}
	
	//跳转团队下应收
	@GetMapping("/listByTeam/{teamId}")
	public String listByTeam(ModelMap map,@PathVariable("teamId")String teamId){
		map.put("teamId", teamId);
	    return "app/contract/receivable/bill_list";
	}
	
}
